home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Information / Digests / CSMP Digest / volume 3 / csmp-digest-v3-051 / doubleCR.1 < prev   
Encoding:
Text File  |  1995-12-31  |  67.6 KB  |  1,901 lines

  1. C.S.M.P. Digest             Fri, 12 Aug 94       Volume 3 : Issue 51
  2.  
  3. Today's Topics:
  4.  
  5.         Controls, Fonts, Dialogs & ResEdit (long)
  6.         Deleting ptr to base not calling dtors of derived
  7.         Icon positions on desktop
  8.         Looking for source code
  9.         Need C source code for recording sound
  10.         OpenPicture with temporary memory?
  11.         QuickTime 2.0 and MIDI
  12.         Tab Patch for TextEdit
  13.         [Q] Increasing stack size?
  14.  
  15.  
  16.  
  17. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  18. (pottier@clipper.ens.fr).
  19.  
  20. The digest is a collection of article threads from the internet newsgroup
  21. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  22. regularly and want an archive of the discussions.  If you don't know what a
  23. newsgroup is, you probably don't have access to it.  Ask your systems
  24. administrator(s) for details.  If you don't have access to news, you may
  25. still be able to post messages to the group by using a mail server like
  26. anon.penet.fi (mail help@anon.penet.fi for more information).
  27.  
  28. Each issue of the digest contains one or more sets of articles (called
  29. threads), with each set corresponding to a 'discussion' of a particular
  30. subject.  The articles are not edited; all articles included in this digest
  31. are in their original posted form (as received by our news server at
  32. nef.ens.fr).  Article threads are not added to the digest until the last
  33. article added to the thread is at least two weeks old (this is to ensure that
  34. the thread is dead before adding it to the digest).  Article threads that
  35. consist of only one message are generally not included in the digest.
  36.  
  37. The digest is officially distributed by two means, by email and ftp.
  38.  
  39. If you want to receive the digest by mail, send email to listserv@ens.fr
  40. with no subject and one of the following commands as body:
  41.     help                        Sends you a summary of commands
  42.     subscribe csmp-digest Your Name    Adds you to the mailing list
  43.     signoff csmp-digest            Removes you from the list
  44. Once you have subscribed, you will automatically receive each new
  45. issue as it is created.
  46.  
  47. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  48. Questions related to the ftp site should be directed to
  49. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  50. digest are available there.
  51.  
  52. Also, the digests are available to WAIS users.  To search back issues
  53. with WAIS, use comp.sys.mac.programmer.src. With Mosaic, use
  54. http://www.wais.com/wais-dbs/comp.sys.mac.programmer.html.
  55.  
  56.  
  57. -------------------------------------------------------
  58.  
  59. >From jcr@mbunix.mitre.org (Rogers)
  60. Subject: Controls, Fonts, Dialogs & ResEdit (long)
  61. Date: 28 Jul 1994 19:31:23 GMT
  62. Organization: The MITRE Corporation, Bedford, MA
  63.  
  64. There's been a bit of traffic lately all having to do with fonts
  65. of dialog items, and I just happen to have been concerned with that
  66. myself lately, and also with controls, so I decided to try to put
  67. together a concise guide to these overlapping topics. It follows.
  68. Everyone feel free to add to it. Or send comments to me and I'll
  69. incorporate.
  70.  
  71. =====================================================================
  72. Creating Controls with ResEdit 2.1.1                     28 July 1994
  73. =====================================================================
  74.  
  75. Here is a guide to creating controls using ResEdit 2.1.1.
  76.  
  77. Please distribute freely, and add to any appropriate FAQs.
  78.  
  79. Please send any comments regarding errors, omissions, etc., to:
  80.  
  81.      Jeff Rogers
  82.      jrogers@mitre.org
  83. _____________________________________________________________________
  84.  
  85. When editing a control in ResEdit, you see a template much like
  86. the ASCII depiction below.
  87.  
  88.  
  89. +-------------------------------------------------------------------+
  90. |=|_|============== CNTL ID = 128 from App_pi.rsrc =================|
  91. |-----------------------------------------------------------------+-|
  92. |                                                                 |^|
  93. |               +-----+ +-----+ +-----+ +-----+    ,-----.        | |
  94. |  BoundsRect   | 391 | | 502 | | 411 | | 652 |   (  Set  )       | |
  95. |               +-----+ +-----+ +-----+ +-----+    '-----'        | |
  96. |               +-----------+                                     | |
  97. |  Value        | 0         |                                     | |
  98. |               +-----------+                                     | |
  99. |                ,-.            ,-.                               | |
  100. |  Visible      ( 0 ) True     (   ) False                        | |
  101. |                '-'            '-'                               | |
  102. |               +-----------+                                     | |
  103. |  Max          | 1         |                                     | |
  104. |               +-----------+                                     | |
  105. |               +-----------+                                     | |
  106. |  Min          | 0         |                                     | |
  107. |               +-----------+                                     | |
  108. |               +-----------+                                     | |
  109. |  ProcID       | 8         |                                     | |
  110. |               +-----------+                                     | |
  111. |               +----------------+                                | |
  112. |  RefCon       | 0              |                                | |
  113. |               +----------------+                                | |
  114. |               +------------------------------------+            | |
  115. |  Title        | Generate Schedule...               |            | |
  116. |               +------------------------------------+            | |
  117. |                                                                 |v|
  118. |_________________________________________________________________|_|
  119.  
  120.  
  121. The proper values for the various fields are not always obvious.
  122. Below is a guide to assigning the correct values.
  123.  
  124. BoundsRect
  125. - --------
  126. This is the control's rectangle in local coordinates. The bounds
  127. are shown in the following order: top, left, bottom, right.
  128.  
  129. Value
  130. - ---
  131. This is the initial value of the control. It should be given one of
  132. the following values, based on the type of control you wish to create:
  133.  
  134.    PushButton  : 0
  135.  
  136.    CheckBox    : 0 = not checked
  137.                  1 = checked
  138.  
  139.    RadioButton : 0 = not selected
  140.                  1 = selected
  141.  
  142.    ScrollBar   : anything between Max and Min, inclusive
  143.  
  144.    PopUpMenu   : The Value parameter of a pop-up menu is used when
  145.                  creating the menu to indicate how the pop-up's
  146.                  title is to be drawn. It should be any ORed
  147.                  combination (sum) of the following:
  148.  
  149.                       0 - left-justified
  150.                       1 - center-justified
  151.                     255 - right-justified
  152.                     256 - bold             4096 - shadow
  153.                     512 - italic           8192 - condensed
  154.                    1024 - underlined      16384 - extended
  155.                    2048 - outlined        32768 - plain
  156.  
  157.                  After the pop-up menu is created, this field
  158.                  will contain the value 1.
  159.  
  160. Visible
  161. - -----
  162. This indicates whether the control is initially visible.
  163.  
  164. Max
  165. - -
  166. This is the maximum value the control may assume. It should
  167. be given one of the following values:
  168.  
  169.    PushButton  : 1
  170.    CheckButton : 1
  171.    RadioButton : 1
  172.    ScrollBar   : any value appropriate to the application
  173.    PopUpMenu   : width in pixels of pop-up menu's title
  174.                  (After the pop-up menu is created, this field
  175.                   will contain the # of items in the pop-up menu.)
  176.  
  177. Min
  178. - -
  179. This is the minimum value the control may assume. It should
  180. be given one of the following values:
  181.  
  182.    PushButton  : 0
  183.    CheckButton : 0
  184.    RadioButton : 0
  185.    ScrollBar   : any value appropriate to the application
  186.    PopUpMenu   : resource ID of menu to pop up
  187.                  (After the pop-up menu is created,
  188.                   this field will contain the value 1.)
  189.  
  190. ProcID
  191. - ----
  192. This indicates which type of control to create, and also which
  193. font to use when drawing the control's title and other text. It
  194. should be given one of the following values:
  195.  
  196.    PushButton,  in system font :    0
  197.                 in window font :    8
  198.  
  199.    CheckButton, in system font :    1
  200.                 in window font :    9
  201.  
  202.    RadioButton, in system font :    2
  203.                 in window font :   10
  204.  
  205.    PopUpMenu ................. : 1008 *
  206.  
  207.    * PopUpMenu behavior can be affected by ORing (summing) the
  208.      ProcID with any of the following:
  209.         1 - don't dynamically adjust pop-up's width to accommodate
  210.             long menu items
  211.         8 - use the grafPort's font to draw the control's text
  212.         4 - ignore "min" field; instead, build a menu listing all
  213.             available resources of the type contained in "refCon"
  214.             field
  215.      Thus the following are valid ProcID values for a popUpMenu:
  216.         1008 - dynamic menu width - system font - menu from "Min"
  217.         1009 - fixed menu width   - system font - menu from "Min"
  218.         1012 - dynamic menu width - system font - list a resType
  219.         1013 - fixed menu width   - system font - list a resType
  220.         1016 - dynamic menu width - window font - menu from "Min"
  221.         1017 - fixed menu width   - window font - menu from "Min"
  222.         1020 - dynamic menu width - window font - list a resType
  223.         1021 - fixed menu width   - window font - list a resType
  224.  
  225. RefCon
  226. - ----
  227. This 32-bit value can be used by your app in any way you wish.
  228.  
  229. For popUpMenus, this field may (depending on the value of "ProcID"
  230. above) be used during creation of the popUpMenu and contain a
  231. 4-character resource type.
  232.  
  233. Title
  234. - ---
  235. This is the control's title. This text shows up inside a pushButton,
  236. or beside a checkBox, radioButton or popUpMenu. For scrollBars it
  237. remains invisible, but still can be used, e.g., to search a window's
  238. controls by title.
  239.  
  240.  
  241. ============================
  242. Dialogs, Controls, and Fonts
  243. ============================
  244.  
  245. A question that often arises is how to get pushButtons, checkBoxes,
  246. radioButtons, and/or popUpMenus in a dialog to be drawn with a font
  247. other than the system font. There are several ways to do this, one
  248. of which is the following:
  249.  
  250. In the DITL editor, rather than creating each control as the type of
  251. control you ultimately want it to be, instead create it as a generic
  252. control. Then, in the CNTL editor, you can specify the ProcID that
  253. will cause the control to be drawn in the dialog's font instead of
  254. the system font. (Thanks to Jens Alfke [jens_alfke@powertalk.apple.com]
  255. for this one.) Otherwise, the dialog manager creates the controls
  256. for you, and it will use ProcID values specifying use of the system
  257. font when drawing the controls. Once these controls are created, there
  258. seems to be no way to change this aspect of them; Apple has provided
  259. a "GetCVariant" call but no "SetCVariant" call.
  260.  
  261. To change the font of statText and editText items, you must take
  262. a different approach. Once the dialog has been created, call a
  263. routine like the following:
  264.  
  265. /**********************************************************************
  266. *
  267. *  FUNCTION:    SetDialogFontAndSize( DialogPtr theDialog,
  268. *                                     short     fontNum,
  269. *                                     short     fontSize    )
  270. *
  271. *  DESCRIPTION: This function sets the font and size to be used
  272. *               subsequently by static-text and edit-text items
  273. *               of a dialog.
  274. *
  275. *  WRITTEN BY:  jarezina@magnus.acs.ohio-state.edu
  276. *               (Jasna M. Arezina-Wilson)
  277. *
  278. *  MODIFIED BY: Jeffrey C. Rogers
  279. *               (jrogers@mitre.org)
  280. *
  281. ****************/
  282.  
  283. void SetDialogFontAndSize( DialogPtr theDialog,
  284.                            short     fontNum,
  285.                            short     fontSize   )
  286. {
  287.   FontInfo   f ;
  288.   GrafPtr    savedPort ;
  289.   
  290.   // Store the current grafPort, then change to the dialog.
  291.   
  292.   GetPort( &savedPort );
  293.   SetPort( theDialog );
  294.   
  295.   // Set up the dialog's grafPort font info.
  296.   
  297.   TextFont( fontNum );
  298.   TextSize( fontSize );
  299.   
  300.   // Deal with the static & edit text items.
  301.   
  302.   GetFontInfo( &f );
  303.   (*((DialogPeek)theDialog)->textH)->txFont = fontNum ;
  304.   (*((DialogPeek)theDialog)->textH)->txSize = fontSize ;
  305.   (*((DialogPeek)theDialog)->textH)->lineHeight = f.ascent + f.descent +
  306.                                                              f.leading ;
  307.   (*((DialogPeek)theDialog)->textH)->fontAscent = f.ascent ;
  308.   
  309.   // Restore previous grafPort.
  310.   
  311.   SetPort( savedPort );
  312. }
  313. /*********************************************************************/
  314.  
  315.  
  316. ---------------------------
  317.  
  318. >From ant@kunikpok.icus.com (handle)
  319. Subject: Deleting ptr to base not calling dtors of derived
  320. Date: Wed, 27 Jul 94 04:41:07 CDT
  321. Organization: Kunikpok Kennels and Komputers (Pet Project)
  322.  
  323. I'm having a problem with destructors. It popped up in a fairly large
  324. hierarchy, and I've boiled it down to the simplest possible below. If
  325. I call a function which accepts a pointer to Base, but the pointer is
  326. of class Derived, when the function deletes the object, it doesn't
  327. call Derived's destructor. If I add a destructor to Base, then it
  328. calls Derived's destructor, then Base's destructor (as I would expect).
  329. This seems like inconsistent behaviour. Is this correct C++? I need to
  330. get it to correctly call Derived's destructor. I don't want to have to
  331. add a destructor to Base (it doesnt need one). If your response is
  332. "just add one anyway", I must point this out: If this is a bug, then
  333. let's find out all the ramifications, instead of just ignoring it.
  334.  
  335. I am using (how on earth did you guess??) Symantec C++ 7.0.3  :)
  336.  
  337. Thanx!
  338.  
  339. - --- test.cp -----
  340.  
  341. class Base { };                 // Empty base class
  342.  
  343. class Derived : public Base     // Derived class, has a constructor
  344. {                               // and destructor
  345. public:
  346.     Derived( void );
  347.     virtual ~Derived( void );
  348.     char* theP;
  349. };
  350.  
  351. Derived::Derived( void )
  352. {
  353.     theP = new char [20000];    // Allocate some space
  354. }
  355.  
  356. Derived::~Derived( void )
  357. {
  358.     if ( theP != 0 )
  359.         delete[] theP;          // Free if allocated
  360. }
  361.  
  362. void    DeleteDerived( Derived* obj )
  363. {
  364.     delete obj;                 // Delete obj
  365. }
  366.  
  367. void    DeleteBase( Base* obj )
  368. {
  369.     delete obj;                 // Delete obj
  370. }
  371.  
  372. main()
  373. {
  374.     Derived*    b1 = new Derived;
  375.     Derived*    b2 = new Derived;
  376.     
  377.     DeleteDerived( b1 );        // Correctly calls ~Derived().
  378.     DeleteBase( b2 );           // Calls *no* destructors
  379.     
  380.     return 0;
  381. }
  382.  
  383. - --- end of test.cp -----
  384.  
  385. - ------------------------------------------------------------------
  386. Chelly Green 'Ant'          <cgreen%podbox.uucp@cs.utexas.edu>
  387.  
  388. +++++++++++++++++++++++++++
  389.  
  390. >From neeri@iis.ee.ethz.ch (Matthias Neeracher)
  391. Date: 28 Jul 1994 15:53:09 GMT
  392. Organization: Integrated Systems Laboratory, ETH, Zurich
  393.  
  394. In article <9q94Pc2w165w@kunikpok.icus.com> ant@kunikpok.icus.com (handle) writes:
  395. > I'm having a problem with destructors. It popped up in a fairly large
  396. > hierarchy, and I've boiled it down to the simplest possible below. If
  397. > I call a function which accepts a pointer to Base, but the pointer is
  398. > of class Derived, when the function deletes the object, it doesn't
  399. > call Derived's destructor. If I add a destructor to Base, then it
  400. > calls Derived's destructor, then Base's destructor (as I would expect).
  401. > This seems like inconsistent behaviour. Is this correct C++?
  402.  
  403. Yes.
  404.  
  405. > I need to get it to correctly call Derived's destructor. I don't want to have
  406. > to add a destructor to Base (it doesnt need one).
  407.  
  408. Well, I'll start with the argument by authority:
  409.  
  410. To quote Bjarne Stroustrup, _The C++ Programming Language_, 2nd edition:
  411. # In general, it is wise to supply a virtual destructor in all classes that
  412. # act as a base class in the sense that objects of derived classes are
  413. # manipulated (and possibly deleted) through a pointer to the base. This is
  414. # almost always the case for classes with even a single virtual function.
  415.  
  416. If that doesn't convince you, think about it in technical terms: How is
  417. the compiler to know to call a destructor of the derived class on a
  418.  
  419. delete base;
  420.  
  421. statement, unless the base class provides a hint in the form of a virtual
  422. destructor.
  423.  
  424. >If your response is "just
  425. > add one anyway", I must point this out: If this is a bug, then let's find out
  426. > all the ramifications, instead of just ignoring it.
  427.  
  428. Your attitude is correct, but it's not a bug.
  429.  
  430. > I am using (how on earth did you guess??) Symantec C++ 7.0.3  :)
  431.  
  432. Awww, leave those poor Symantec compiler guys alone for a change and let them
  433. fix the bugs that *are* there (As the "*=" thread has shown, it is hard enough
  434. to convince them of those already. The Metrowerks guys, on the other hand,
  435. didn't explicitely admit that it was a bug, but promised to fix it :-).
  436.  
  437. Matthias
  438.  
  439. - ---
  440. Matthias Neeracher <neeri@iis.ee.ethz.ch> http://err.ethz.ch/members/neeri.html
  441.   "Paranotions, which designate constructs, may now contain metanotions and
  442.    ``hypernotions'' have been introduced in order to designate protonotions"
  443.                 -- A. van Wijngaarden et al., _ALGOL 68 Revised Report_
  444.  
  445. +++++++++++++++++++++++++++
  446.  
  447. >From nagle@netcom.com (John Nagle)
  448. Date: Fri, 29 Jul 1994 04:08:28 GMT
  449. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  450.  
  451. neeri@iis.ee.ethz.ch (Matthias Neeracher) writes:
  452. >In article <9q94Pc2w165w@kunikpok.icus.com> ant@kunikpok.icus.com (handle) writes:
  453. >> I'm having a problem with destructors. It popped up in a fairly large
  454. >> hierarchy, and I've boiled it down to the simplest possible below. If
  455. >> I call a function which accepts a pointer to Base, but the pointer is
  456. >> of class Derived, when the function deletes the object, it doesn't
  457. >> call Derived's destructor. If I add a destructor to Base, then it
  458. >> calls Derived's destructor, then Base's destructor (as I would expect).
  459. >> This seems like inconsistent behaviour. Is this correct C++?
  460.  
  461. >Yes.
  462.  
  463.      That's right, but the rationale for it working this way is wierd.
  464.  
  465.      The trouble comes from the C++ design decision that classes and
  466. structs are the same, plus the design decision that classes that don't
  467. use "C++ features" have compatible storage layout with C structs.
  468.  Logically, all destructors should be virtual, but that would force
  469. all classes to have the machinery for virtual functions, in case somebody
  470. later derived a class from that class.  This would break C data structure
  471. compatibility.
  472.  
  473.      It really should be an error to derive a class with a destructor
  474. from a class which does not have a virtual destructor.  If you want
  475. normal destructor semantics, you have to have virtual destructors all the way
  476. down to the base class.  This is easily checkable and should be
  477. checked, rather than being viewed as a rite of passage for C++ programmers.
  478.  
  479.                     John Nagle
  480.  
  481. +++++++++++++++++++++++++++
  482.  
  483. >From sokoloff@mv.mv.com (Jim Sokoloff)
  484. Date: Thu, 28 Jul 1994 20:04:24 GMT
  485. Organization: MV Communications, Inc.
  486.  
  487. In article <9q94Pc2w165w@kunikpok.icus.com>,
  488. handle <ant@kunikpok.icus.com> wrote:
  489. >I'm having a problem with destructors. It popped up in a fairly large
  490. >hierarchy, and I've boiled it down to the simplest possible below. If
  491. >I call a function which accepts a pointer to Base, but the pointer is
  492. >of class Derived, when the function deletes the object, it doesn't
  493. >call Derived's destructor. If I add a destructor to Base, then it
  494. >calls Derived's destructor, then Base's destructor (as I would expect).
  495. >This seems like inconsistent behaviour. Is this correct C++? I need to
  496. >get it to correctly call Derived's destructor. I don't want to have to
  497. >add a destructor to Base (it doesnt need one). If your response is
  498. >"just add one anyway", I must point this out: If this is a bug, then
  499. >let's find out all the ramifications, instead of just ignoring it.
  500. [Sample deleted]
  501. AS far as I know, this is correct C++. Base has no dtor, therefore, when 
  502. you delete a Base *, there is no dtor to call. Therefore, your compiler is
  503. doing the right thing. Add a virtual dtor to Base anyway. This will cause the
  504. correct thing to happen. (From your perspective, meaning Derived dtor is 
  505. called. From the C++ perspective, the correct thing is already happening, and
  506. you have a bug in your code...)
  507.  
  508. - -Jim
  509.  
  510.  
  511.  
  512. +++++++++++++++++++++++++++
  513.  
  514. >From s2361905@techst02.technion.ac.il (Ben Hekster)
  515. Date: Thu, 28 Jul 1994 19:37:44 GMT
  516. Organization: Technion, Israel Institute of Technology
  517.  
  518. Hi--
  519.  
  520. >If
  521. >I call a function which accepts a pointer to Base, but the pointer is
  522. >of class Derived, when the function deletes the object, it doesn't
  523. >call Derived's destructor. If I add a destructor to Base, then it
  524. >calls Derived's destructor, then Base's destructor (as I would expect).
  525. >[...] Is this correct C++?
  526.  
  527. Yes, this is correct C++.  If you expect to be able to call member
  528. functions that you override in derived classes, you must declare
  529. the member function `virtual' in the base type.  Note that this
  530. is true for any member function, not just destructors.  I.e., if you
  531. have
  532.  
  533.     class Base { void f(); };
  534.  
  535.     class Derived : public Base { virtual void f(); };
  536.  
  537. then any application of f() to a Base binds to Base::f().  If you
  538. want the binding to be dynamic, you must supply the `virtual'.
  539. By omitting it you are implying that either you do not expect this
  540. function to be overridden, or that you don't want/need overridden
  541. versions to be called.
  542.  
  543.     The questionable thing here is why the compiler doesn't
  544. warn about the redeclaration of f().  Possibly because of C
  545. compatibility reasons.  MPW cfront doesn't either, even with maximum
  546. warnings.
  547.  
  548.     In general, if your class has virtual members, it should
  549. have a virtual destructor, even if the destructor action itself is
  550. trivial.  The ARM warns about this, to avoid exactly the problem
  551. you are having now.
  552.  
  553. Ben
  554.  
  555.  
  556. +++++++++++++++++++++++++++
  557.  
  558. >From afcjlloyd@aol.com (AFC JLloyd)
  559. Date: 29 Jul 1994 02:11:07 -0400
  560. Organization: America Online, Inc. (1-800-827-6364)
  561.  
  562. In article <nagleCtoou4.Bxw@netcom.com>, nagle@netcom.com (John Nagle)
  563. writes:
  564.  
  565. >neeri@iis.ee.ethz.ch (Matthias Neeracher) writes:
  566. >>In article <9q94Pc2w165w@kunikpok.icus.com> ant@kunikpok.icus.com
  567. (handle) writes:
  568. >>> I'm having a problem with destructors. It popped up in a fairly large
  569. >>> hierarchy, and I've boiled it down to the simplest possible below. If
  570. >>> I call a function which accepts a pointer to Base, but the pointer is
  571. >>> of class Derived, when the function deletes the object, it doesn't
  572. >>> call Derived's destructor. If I add a destructor to Base, then it
  573. >>> calls Derived's destructor, then Base's destructor (as I would
  574. expect).
  575. >>> This seems like inconsistent behaviour. Is this correct C++?
  576. >
  577. >>Yes.
  578. >
  579. >     That's right, but the rationale for it working this way is wierd.
  580. >
  581. >     The trouble comes from the C++ design decision that classes and
  582. >structs are the same, plus the design decision that classes that don't
  583. >use "C++ features" have compatible storage layout with C structs.
  584. > Logically, all destructors should be virtual, but that would force
  585. >all classes to have the machinery for virtual functions, in case somebody
  586. >later derived a class from that class.  This would break C data structure
  587. >compatibility.
  588. >
  589. >     It really should be an error to derive a class with a destructor
  590. >from a class which does not have a virtual destructor.  If you want
  591. >normal destructor semantics, you have to have virtual destructors all the
  592. way
  593. >down to the base class.  This is easily checkable and should be
  594. >checked, rather than being viewed as a rite of passage for C++
  595. programmers.
  596.  
  597. I think it's a little more complicated than this.  I can think of lots of
  598. uses for classes that don't need any virtual functions, but need
  599. destructors (e.g. resource acquisition classes).  There is no point in
  600. making the destructor be virtual in such a case, and doing so generates a
  601. whole vtbl when none is needed, so the overhead cost is actually quite
  602. high (much more so than adding one entry to an already existing vtbl).
  603.  
  604. However, I agree with the idea that it should be an error to derive from
  605. classes that don't have virtual destructors.  Since the compiler doesn't
  606. enforce it (what a great optional warning!), the only thing you can do is
  607. add it to your list of coding guidelines.  Scott Meyer's is now writing a
  608. column for the C++ Report which continues the set of guidelines he
  609. established in his (truly excellent) book "Effective C++: 50 Specific Ways
  610. to Improve Your Programs and Designs".  His most recent column presents
  611. the guideline: "Avoid having concrete classes inherit from concrete
  612. classes".  Couple this with the guideline "Make destructors virtual in
  613. abstract base classes", and you're well covered.
  614.  
  615. By the way, if the guideline against deriving from concrete classes seems
  616. wrong to you, I highly recommend you read the article (July-August 94
  617. issue of C++ Report, should still be on the newstands).
  618.  
  619. Jim Lloyd
  620. afcjlloyd@aol.com
  621.  
  622.  
  623. ---------------------------
  624.  
  625. >From eajohnsn@blue.weeg.uiowa.edu (Eric Johnson)
  626. Subject: Icon positions on desktop
  627. Date: 25 Jul 1994 18:12:33 -0500
  628. Organization: University of Iowa, Iowa City, IA, USA
  629.  
  630. Hope this isn't too obvious, but I lack most reference sources.  I am 
  631. curious how programs like UnderWare know where on the screen the 
  632. different icons and folders are kept.  If I wanted to write a program 
  633. that would move the desktop icons around (or copy the screen and pretend 
  634. to move them), where do I find their positions?  Any tips or pointers to 
  635. the correct IM volume would be great.
  636.  
  637. Eric Johnson                eajohnsn@blue.weeg.uiowa.edu
  638. Program in Genetics
  639. University of Iowa
  640.  
  641.  
  642.  
  643. +++++++++++++++++++++++++++
  644.  
  645. >From zobkiw@datawatch.com (joe zobkiw)
  646. Date: Tue, 26 Jul 1994 15:19:14 GMT
  647. Organization: Datawatch Corporation
  648.  
  649. In article <311gt1$2g57@blue.weeg.uiowa.edu>, eajohnsn@blue.weeg.uiowa.edu
  650. (Eric Johnson) wrote:
  651.  
  652. > Hope this isn't too obvious, but I lack most reference sources.  I am 
  653. > curious how programs like UnderWare know where on the screen the 
  654. > different icons and folders are kept.  If I wanted to write a program 
  655. > that would move the desktop icons around (or copy the screen and pretend 
  656. > to move them), where do I find their positions?  Any tips or pointers to 
  657. > the correct IM volume would be great.
  658.  
  659. For each volume, recurse through the "Desktop folder" and perform an
  660. FSpGetFInfo on each file. The fdLocation gives you the location of the
  661. topLeft corner of the icon. For directories (if you use FSpGetDInfo) it is
  662. the frLocation field.
  663.  
  664. ___________________________________________________________
  665. _/_/_/_/   Joe Zobkiw                                   ,,,
  666.     _/     Senior Software Engineer                     - -
  667.   _/       Datawatch Corporation                         L
  668. _/_/_/_/   zobkiw@datawatch.com                          -
  669.  
  670. +++++++++++++++++++++++++++
  671.  
  672. >From dkj@apple.com (Dave Johnson)
  673. Date: Tue, 26 Jul 1994 17:54:41 GMT
  674. Organization: Apple Computer
  675.  
  676. In article <zobkiw-2607941019140001@zobkiw.datawatch.com>,
  677. zobkiw@datawatch.com (joe zobkiw) wrote:
  678.  
  679. > For each volume, recurse through the "Desktop folder" and perform an
  680. > FSpGetFInfo on each file. The fdLocation gives you the location of the
  681. > topLeft corner of the icon. For directories (if you use FSpGetDInfo) it is
  682. > the frLocation field.
  683.  
  684. Note also that with the scriptable Finder (7.5+, I think) you can get/set
  685. the locations of items via AppleScript or Apple Events real easy . . .
  686.  
  687. +++++++++++++++++++++++++++
  688.  
  689. >From macneils@aol.com (MacneilS)
  690. Date: 28 Jul 1994 20:44:03 -0400
  691. Organization: America Online, Inc. (1-800-827-6364)
  692.  
  693. In article <mouse-280794174850@ppp-83-19.bu.edu>, mouse@bu.edu (Matt Mick)
  694. writes:
  695.  
  696. >>>>>>
  697. Look at the NIM:Files.  It tells you how to get the h and v pos of the
  698. file.  I think, if I remember correctly, that is for the Icon!
  699. <<<<<<
  700.  
  701. You want to use HGetFInfo(). This will give you all of the information
  702. that the Finder itself uses for the posistion of icons.
  703.  
  704. Take Care,
  705. MacneilS@aol.com
  706.  
  707. +++++++++++++++++++++++++++
  708.  
  709. >From grobbins@apple.com (Grobbins)
  710. Date: 28 Jul 1994 21:06:31 -0700
  711. Organization: Skunkworks
  712.  
  713. In article <mouse-280794174850@ppp-83-19.bu.edu>,
  714. Matt Mick <mouse@bu.edu> wrote:
  715. >In article <311gt1$2g57@blue.weeg.uiowa.edu>, eajohnsn@blue.weeg.uiowa.edu
  716. >(Eric Johnson) wrote:
  717. >> Hope this isn't too obvious, but I lack most reference sources.  I am 
  718. >> curious how programs like UnderWare know where on the screen the 
  719. >> different icons and folders are kept.
  720. >
  721. >Look at the NIM:Files.  It tells you how to get the h and v pos of the
  722. >file.  I think, if I remember correctly, that is for the Icon!
  723.  
  724. The fdLocation field of a file's FInfo (returned by PBGetCatInfo and
  725. FSpGetFInfo, among other calls) may have the icon location.  But because
  726. the Finder ruthlessly caches its file information, the numbers on
  727. disk may not be accurate and cannot reliably be used to determine or
  728. set the icon position.
  729.  
  730. With the Scriptable Finder, you can use AppleScript to have the Finder
  731. get and set the positions of icons.  But any commercial products now
  732. that "know" where the icons reside are probably doing hacky skanky things
  733. to get that information reliably, 'cause the non-scriptable versions of
  734. the Finder are really unfriendly about sharing the knowledge.
  735.  
  736. Grobbins                grobbins@apple.com
  737.  
  738. Usual disclaimers apply.
  739.  
  740.  
  741. +++++++++++++++++++++++++++
  742.  
  743. >From mouse@bu.edu (Matt Mick)
  744. Date: Thu, 28 Jul 1994 17:48:49 -0500
  745. Organization: Boston University
  746.  
  747. In article <311gt1$2g57@blue.weeg.uiowa.edu>, eajohnsn@blue.weeg.uiowa.edu
  748. (Eric Johnson) wrote:
  749.  
  750. > Hope this isn't too obvious, but I lack most reference sources.  I am 
  751. > curious how programs like UnderWare know where on the screen the 
  752. > different icons and folders are kept.  If I wanted to write a program 
  753. > that would move the desktop icons around (or copy the screen and pretend 
  754. > to move them), where do I find their positions?  Any tips or pointers to 
  755. > the correct IM volume would be great.
  756. > Eric Johnson                eajohnsn@blue.weeg.uiowa.edu
  757. > Program in Genetics
  758. > University of Iowa
  759.  
  760. Look at the NIM:Files.  It tells you how to get the h and v pos of the
  761. file.  I think, if I remember correctly, that is for the Icon!
  762.  
  763. --matt
  764.  
  765. ---------------------------
  766.  
  767. >From rweber@helium.Gas.UUG.Arizona.EDU (Roygena R Weber)
  768. Subject: Looking for source code
  769. Date: 26 Jul 1994 22:52:09 GMT
  770. Organization: University of Arizona UNIX Users Group
  771.  
  772.  
  773. Could somebody point me to any ftp sites (besides umich and sumex) that 
  774. contain Macintosh source code? Pascal is preferred, but C is okay, too.
  775.  
  776. Also, is there a FAQ for this group? Where can it be found?
  777.  
  778. Thanks,
  779.  
  780. JACOB WEBER------------------------------------------*
  781.  \   Tucson, Arizona                    Where's       \
  782.   \   rweber@gas.uug.arizona.edu         My            \
  783.    \   CompuServe: 72303,3540             Thing?        \
  784.     *----------------------------------------------------*
  785.  
  786.  
  787. +++++++++++++++++++++++++++
  788.  
  789. >From tg3@u.washington.edu (Thurman Gillespy III)
  790. Date: Wed, 27 Jul 1994 09:21:22 -0800
  791. Organization: Dept of Radiology, Univ of Washington
  792.  
  793. In article <31442p$enm@news.CCIT.Arizona.EDU>,
  794. rweber@helium.Gas.UUG.Arizona.EDU (Roygena R Weber) wrote:
  795.  
  796. > Could somebody point me to any ftp sites (besides umich and sumex) that 
  797. > contain Macintosh source code? Pascal is preferred, but C is okay, too.
  798. > Also, is there a FAQ for this group? Where can it be found?
  799. > Thanks,
  800. > JACOB WEBER------------------------------------------*
  801. >  \   Tucson, Arizona                    Where's       \
  802. >   \   rweber@gas.uug.arizona.edu         My            \
  803. >    \   CompuServe: 72303,3540             Thing?        \
  804. >     *----------------------------------------------------*
  805.  
  806. You should get the Apprentice CD-ROM from Celestin Company. This CD-ROM
  807. is PACKED with source code, demos, and various utilites. Its a bargain
  808. at $35.
  809.  
  810.   Celestin Company
  811.   celestin@pt.olympus.net
  812.   (800) 835-5514 oders
  813.   file://speedway.net/pub/celestin/www/Celestin.html
  814.  
  815. -- 
  816. Thurman Gillespy III, MD         |  tg3@u.washington.edu
  817. Department of Radiology, SB-05   |  (206)543-3320 voice
  818. University of Washington         |  (206)543-6317 fax
  819. Seattle, WA 98195
  820.  
  821. +++++++++++++++++++++++++++
  822.  
  823. >From kenlong@netcom.com (Ken Long)
  824. Date: Wed, 27 Jul 1994 16:02:13 GMT
  825. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  826.  
  827. ftp devtools.symantec.com - has C source.
  828. ftp gatekeeper.dec.com - pub/DEC/Modula-2/m2.tar.Z
  829. ftp ftp.cwi.nl - Pascal
  830. ftp.eb.ele.tue.nl - pub/src/pascal/pasos2*
  831. ftp ftp.uu.net - usenet comp sources
  832. ftp zippy.nimh.nih.gov - image (Pascal - several versions)
  833. ftp nic.switch.ch /software/mac
  834. ftp uniwa.uwa.edu.au - POV
  835. ftp ftp.dartmouth.edu /pub/mac
  836. ftp midway.uchicago.edu /pub/OzTex   
  837. ftp ftpbio.bgsu.edu in pub/mac/alt.sources.mac
  838. ftp ftp.cc.umanitoba.ca /mac/develop
  839. ftp oddjob.uchicago.edu. 
  840. ftp magoo.uwsuper.edu - MacWT .04
  841. ftp csvax.cs.caltech.edu - pub/p2c-1.20.tar.Z.
  842. ftp bigbird.csd.scarolina.edu -  pub/mac - JWWalker
  843. ftp mrcnext.cso.uiuc.edu - pub/mac (old P, B, C, M2, F, A and HC)
  844. ftp prep.ai.mit.edu  pub/gnu/etc/GNU
  845.  
  846. That oughta get you started.
  847.  
  848. Get any ftp site lists that are available and connect and see what they 
  849. have.  The MacFTP List is pretty well known, but there are others.
  850.  
  851. I found one site by reading comp.sources.wanted, and a referral by 
  852. someone there.  That group is mostly non-Mac, but I get site tips from 
  853. messages.  Whenever I read, "So-and-so file is available at ftp.xxx.xxx" 
  854. and it's a site I haven't look on yet, I save that address in NotePad++ 
  855. (which I run in addition to my telecom program) and connect after I get 
  856. out of tin.
  857.  
  858. Always get the site indexes - description files too, if they have them.  
  859. Or start a screen capture as soon as you connect.  I save all the site 
  860. directory lists in a folder on my desktop called "Indexes."
  861.  
  862. Get on some services, too.  AOL has sources you won't find anywhere else, 
  863. and other services may be the same.  You don't have to remain a meber 
  864. for life - just long enough to get all their unique source code, if any.
  865.  
  866. -Ken-
  867.  
  868.  
  869. +++++++++++++++++++++++++++
  870.  
  871. >From Bill Melotti <bill.melotti@rl.ac.uk>
  872. Date: 27 Jul 1994 17:27:59 GMT
  873. Organization: Rutherford Appleton Labs (EPSRC)
  874.  
  875. Looking for source code
  876.  
  877. Try ftp.switch.ch
  878.  
  879. Bill
  880. - -----------------------------------------
  881. Bill Melotti                   Rm2.09, R68,
  882. Electronics Engineer           D-RAL,
  883. System Design Group            Chilton,
  884. Electronics Division           Nr. Didcot,
  885. Rutherford Appleton Lab        OX11 0QX
  886.  
  887. V (0235) 446815, F (0235) 445753
  888. - ----------------------
  889. All these opinions are mine and no one elses
  890.  
  891. +++++++++++++++++++++++++++
  892.  
  893. >From kenlong@netcom.com (Ken Long)
  894. Date: Wed, 27 Jul 1994 19:48:34 GMT
  895. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  896.  
  897. : You should get the Apprentice CD-ROM from Celestin Company. This CD-ROM
  898. : is PACKED with source code, demos, and various utilites. Its a bargain
  899. : at $35.
  900.  
  901. If you're going the CD route, EduCarp (no typo) has source on CD's and 
  902. disks, and MacTech has there source CD available for a couple C notes - 
  903. that's U.S. currency, not music tones.  Yeah, you can have it for a 
  904. song!  Two C notes!
  905.  
  906. Meanwhile, back at reality, there's also the AMUG CD, but theirs and 
  907. EduCarp's contain stuff that's posted.  MacTechs is from their mag.
  908.  
  909. -Ken-
  910.  
  911. +++++++++++++++++++++++++++
  912.  
  913. >From quesnel@sound.music.mcgill.ca (Rene Quesnel)
  914. Date: Wed, 27 Jul 1994 18:21:03 GMT
  915. Organization: Faculty of Music, McGill University
  916.  
  917. Roygena R Weber (rweber@helium.Gas.UUG.Arizona.EDU) wrote:
  918.  
  919. > Could somebody point me to any ftp sites (besides umich and sumex) that 
  920. > contain Macintosh source code? Pascal is preferred, but C is okay, too.
  921.  
  922. Try ftp.apple.com in directory dts/mac/sc. It contains code snippets and
  923. more elaborate examples, some in pascal, a  lot in C and C++. They also
  924. have the source code for the book Macintosh Programming Secrets by Knaster
  925. and Rollin.
  926.  
  927. You can get the csmp FAQ at nada.kth.se in directory
  928. pub/hacks/mac-faq/
  929.  
  930. Rene Quesnel
  931.  
  932. Music Technology and Sound Recording Areas
  933. Faculty of Music, McGill University
  934. Montreal, QC, Canada
  935. e-mail: quesnel@music.mcgill.ca
  936.  
  937.  
  938. +++++++++++++++++++++++++++
  939.  
  940. >From celestin@pt.olympus.net (Paul Celestin)
  941. Date: Thu, 28 Jul 1994 12:54:41 -0700
  942. Organization: Celestin Company
  943.  
  944. In article <31442p$enm@news.CCIT.Arizona.EDU>,
  945. rweber@helium.Gas.UUG.Arizona.EDU (Roygena R Weber) wrote:
  946.  
  947. > Could somebody point me to any ftp sites (besides umich and
  948. > sumex) that  contain Macintosh source code? Pascal is
  949. > preferred, but C is okay, too.
  950.  
  951. Here is a list of a few places I know of:
  952.  
  953. ftp://ftpbio.bgsu.edu/
  954. ftp://daemon.ncsa.uiuc.edu/TCL/
  955. ftp://ftp.luth.se/pub/mac/developer/
  956. ftp://f.ms.uky.edu/pub/mac/sources/
  957. ftp://ftp.ncsa.uiuc.edu/Mac/
  958. ftp://ics.uci.edu/mac/think-c/
  959. ftp://nic.switch.ch/software/mac/src/
  960. ftp://zippy.nimh.nih.gov/pub/nih-image/
  961. ftp://oak.oakland.edu/pub/macintosh/code/
  962. ftp://plains.nodak.edu/pub/mac/pub/programming/src/
  963. ftp://ssyx.ucsc.edu/pub/mac/
  964. ftp://ftp.cc.umanitoba.ca/Mac-Develop/
  965. ftp://ftp.netcom.com/pub/xplain/
  966.  
  967. -- 
  968. celestin@pt.olympus.net              (Paul Celestin, Celestin Company)
  969. Home of Apprentice - the Mac Programmer Source Code & Utilities CD-ROM
  970. finger me for more information about Celestin Company and its products
  971.  
  972. ---------------------------
  973.  
  974. >From smithjim@aol.com (Smith Jim)
  975. Subject: Need C source code for recording sound
  976. Date: 28 Jul 1994 18:12:06 -0400
  977. Organization: America Online, Inc. (1-800-827-6364)
  978.  
  979. I am looking for source code in C that demonstrates how to record sound
  980. with the
  981. microphone input port.  Any ideas?  Thanks.
  982.  
  983. Jim 
  984.  
  985. +++++++++++++++++++++++++++
  986.  
  987. >From mars@netcom.com (Darren Giles)
  988. Date: Fri, 29 Jul 1994 21:40:31 GMT
  989. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  990.  
  991. In article <319afm$sh@search01.news.aol.com>,
  992. Smith Jim <smithjim@aol.com> wrote:
  993. >I am looking for source code in C that demonstrates how to record sound
  994. >with the
  995. >microphone input port.  Any ideas?  Thanks.
  996. >
  997. >Jim 
  998.  
  999. Here's a section of code which does what I believe you're looking for,
  1000. asynchronously, and writes the sampled sound to a resource.  Enjoy!
  1001.  
  1002. - Darren
  1003.  
  1004. #define    SND_BUFFER_SIZE        (15*11000)
  1005.  
  1006. typedef struct {
  1007.     short                    nbr_channels;
  1008.     Fixed                    sample_rate;
  1009.     short                    sample_size;
  1010.     OSType                    compression_type;
  1011. } snd_in_info;
  1012.  
  1013.  
  1014. ////////////////////////////////////////////////////////////////////////////
  1015. OSErr my_sound_start_recording () {
  1016.     OSErr                    myErr;
  1017.     long                    buff_size;
  1018.  
  1019.  
  1020.     if (!g_snd_dev_refNum)
  1021.         return -1;
  1022.         
  1023.     //    Find out default settings
  1024.     myErr= SPBGetDeviceInfo (g_snd_dev_refNum, siNumberChannels, (char*) &g_snd_info.nbr_channels);
  1025.     TST_MYERR_RTN ("calling SPBGetDeviceInfo")
  1026.     myErr= SPBGetDeviceInfo (g_snd_dev_refNum, siSampleRate, (char*) &g_snd_info.sample_rate);
  1027.     TST_MYERR_RTN ("calling SPBGetDeviceInfo")
  1028.     myErr= SPBGetDeviceInfo (g_snd_dev_refNum, siSampleSize, (char*) &g_snd_info.sample_size);
  1029.     TST_MYERR_RTN ("calling SPBGetDeviceInfo")
  1030.     myErr= SPBGetDeviceInfo (g_snd_dev_refNum, siCompressionType, (char*) &g_snd_info.compression_type);
  1031.     TST_MYERR_RTN ("calling SPBGetDeviceInfo")
  1032.     
  1033.     //    Set to record at 11kHz
  1034.     g_snd_info.sample_rate = rate11khz;
  1035.     myErr= SPBSetDeviceInfo (g_snd_dev_refNum, siSampleRate, (char*) &g_snd_info.sample_rate);
  1036.     TST_MYERR_RTN ("calling SPBSetDeviceInfo")
  1037.     myErr= SPBGetDeviceInfo (g_snd_dev_refNum, siSampleRate, (char*) &g_snd_info.sample_rate);
  1038.     TST_MYERR_RTN ("calling SPBGetDeviceInfo")
  1039.  
  1040.     //    Create new sound handle & setup for SND_RSRC_TYPE rsrc header
  1041.     g_snd_hdl= NewHandle (SND_BUFFER_SIZE);
  1042.     TST_NIL_RTN (g_snd_hdl, "allocating g_snd_hdl handle");
  1043.     myErr= SetupSndHeader (g_snd_hdl, g_snd_info.nbr_channels,
  1044.                 g_snd_info.sample_rate, g_snd_info.sample_size, 
  1045.                 g_snd_info.compression_type, 60, 0, &g_snd_header_len);
  1046.     TST_MYERR_RTN ("calling SetupSndHeader")
  1047.     buff_size= GetHandleSize (g_snd_hdl) - g_snd_header_len;
  1048.     HLockHi (g_snd_hdl);
  1049.     
  1050.     //    Setup & call sound input recording
  1051.     g_snd_PB.inRefNum=            g_snd_dev_refNum;
  1052.     g_snd_PB.count=                buff_size;
  1053.     g_snd_PB.milliseconds=        0;
  1054.     g_snd_PB.bufferLength=        buff_size;
  1055.     g_snd_PB.bufferPtr=            (Ptr) (*g_snd_hdl + g_snd_header_len);
  1056.     g_snd_PB.completionRoutine=    nil;
  1057.     g_snd_PB.interruptRoutine=    nil;
  1058.     g_snd_PB.userLong=            0;
  1059.     g_snd_PB.error=                noErr;
  1060.     g_snd_PB.unused1=            0;
  1061.     myErr= SPBRecord (&g_snd_PB, true);
  1062.     TST_MYERR_RTN ("calling SPBRecord")
  1063.  
  1064.     return noErr;
  1065. }
  1066.  
  1067.  
  1068. ////////////////////////////////////////////////////////////////////////////
  1069. OSErr my_sound_stop_recording () {
  1070.     OSErr                    myErr;
  1071.     long                    lead_size;
  1072.     uchar                    *sample;
  1073.  
  1074.  
  1075.     if (!g_snd_dev_refNum)
  1076.         return -1;
  1077.         
  1078.     //    Make sure we're done reading
  1079.     myErr= SPBStopRecording (g_snd_dev_refNum);
  1080.     TST_MYERR_RTN ("calling SPBStopRecording")
  1081.     
  1082.     //    Update snd info for # bytes actually kept
  1083.     HUnlock (g_snd_hdl);
  1084.     SetHandleSize (g_snd_hdl, g_snd_header_len+g_snd_PB.count);
  1085.     myErr= SetupSndHeader (g_snd_hdl, g_snd_info.nbr_channels,
  1086.                 g_snd_info.sample_rate, g_snd_info.sample_size, 
  1087.                 g_snd_info.compression_type, 60, g_snd_PB.count,
  1088.                 &g_snd_header_len);
  1089.     
  1090.     //    Play it back
  1091.     myErr= SndPlay (nil, g_snd_hdl, 0);
  1092.     TST_MYERR_RTN ("calling SndPlay")
  1093.     
  1094.     return noErr;
  1095. }
  1096.  
  1097.  
  1098. ////////////////////////////////////////////////////////////////////////////
  1099. OSErr my_sound_cancel_recording () {
  1100.     OSErr                    myErr;
  1101.  
  1102.  
  1103.     //    Make sure we're done reading
  1104.     if (g_snd_dev_refNum) {
  1105.         myErr= SPBStopRecording (g_snd_dev_refNum);
  1106.         TST_MYERR_RTN ("calling SPBStopRecording")
  1107.     }
  1108.     
  1109.     if (g_snd_hdl) {
  1110.         ReleaseResource (g_snd_hdl);
  1111.         DisposeHandle (g_snd_hdl);
  1112.         g_snd_hdl= nil;
  1113.     }
  1114.     
  1115.     return noErr;
  1116. }
  1117.  
  1118. +++++++++++++++++++++++++++
  1119.  
  1120. >From kenlong@netcom.com (Ken Long)
  1121. Date: Fri, 29 Jul 1994 20:25:21 GMT
  1122. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  1123.  
  1124. On AOL, in the MDV lib., theres an aiff recorder source.  Apple's 
  1125. SoundApp.pas source has some record routine (s), as I recall.
  1126.  
  1127. On AOL, go to the file search (keyword: quickfinder) click the developer 
  1128. box and type in: sound
  1129. and hit return.  That should lead you to some.
  1130.  
  1131. Also, there's source on AOL not listed in the MDV library.  Type in 
  1132. search word: source
  1133. in other directories than MDV, to track it down.
  1134.  
  1135. -Ken-
  1136.  
  1137. +++++++++++++++++++++++++++
  1138.  
  1139. >From Mark Hanrek <hanrek@cts.com>
  1140. Date: Fri, 29 Jul 1994 20:45:36 GMT
  1141. Organization: The Information Workshop
  1142.  
  1143. In article <319afm$sh@search01.news.aol.com> Smith Jim, smithjim@aol.com
  1144. writes:
  1145.  
  1146. >I am looking for source code in C that demonstrates how to record 
  1147. > sound with the microphone input port.  Any ideas?  Thanks.
  1148.  
  1149. Jim,
  1150.  
  1151. There should be at least one source code example in the Development File
  1152. Libraries.
  1153.  
  1154. There are lots and lots of examples, though, on the Developer CD.  If you
  1155. know someone with direct internet access, you can have them download a few
  1156. from ftp.apple.com.
  1157.  
  1158. Hope this helps.
  1159.  
  1160. Mark Hanrek
  1161.  
  1162. ---------------------------
  1163.  
  1164. >From AIKEN <INRA000@MUSICB.MCGILL.CA>
  1165. Subject: OpenPicture with temporary memory?
  1166. Date: Tue, 26 Jul 1994 20:00:30 GMT
  1167. Organization: McGill University
  1168.  
  1169. Hiya,
  1170.  
  1171.     Can anyone think of a reasonably robust way of coercing OpenPicture
  1172. into allocating its picture using temporary memory? I was surprised to
  1173. find no straightforward way of doing this, considering may QD features,
  1174. such as GWorlds, have support for temporary memory.
  1175.  
  1176.     Any help appreciated.
  1177.  
  1178.     Cheers,
  1179.  
  1180.     Mark Aiken
  1181.     inra@musicb.mcgill.ca
  1182.  
  1183.  
  1184. +++++++++++++++++++++++++++
  1185.  
  1186. >From giles@med.cornell.edu (Aaron Giles)
  1187. Date: Wed, 27 Jul 1994 01:56:18 -0400
  1188. Organization: Cornell University Medical College
  1189.  
  1190. In article <26JUL94.16209243.0081@VM1.MCGILL.CA>, AIKEN
  1191. <INRA000@MUSICB.MCGILL.CA> wrote:
  1192.  
  1193. >     Can anyone think of a reasonably robust way of coercing OpenPicture
  1194. > into allocating its picture using temporary memory? I was surprised to
  1195. > find no straightforward way of doing this, considering may QD features,
  1196. > such as GWorlds, have support for temporary memory.
  1197.  
  1198. I don't know how "kosher" this is, but I've done it successfully in a
  1199. shipping app without any apparent problems.  At least, it *seems* simple
  1200. enough. :-)  Here's the gist:
  1201.  
  1202. THz tempZone, oldZone;
  1203. PicHandle thePict;
  1204. OSErr theErr;
  1205.  
  1206. // allocate a handle in temp memory, and retrieve the temporary zone from that
  1207. thePict = (PicHandle)TempNewHandle(4, &theErr);
  1208. if (theErr == noErr && thePict) {
  1209.    tempZone = HandleZone((Handle)thePict);
  1210.    DisposeHandle((Handle)thePict);
  1211.  
  1212.    // open the picture
  1213.    oldZone = GetZone();
  1214.    SetZone(tempZone);
  1215.    thePict = OpenCPicture(&myParams);
  1216.    SetZone(oldZone);
  1217. }
  1218.  
  1219. Aaron
  1220. -- 
  1221. Aaron Giles (giles@med.cornell.edu)
  1222. Power Macintosh Developer, Cornell University Medical College
  1223. JPEGView home page: http://www.med.cornell.edu/jpegview.html
  1224. JPEGView FTP site:   ftp://ftp.med.cornell.edu/pub/aarong/jpegview/
  1225.  
  1226. +++++++++++++++++++++++++++
  1227.  
  1228. >From Jens Alfke <jens_alfke@powertalk.apple.com>
  1229. Date: Wed, 27 Jul 1994 20:28:49 GMT
  1230. Organization: Apple Computer
  1231.  
  1232. In article <26JUL94.16209243.0081@VM1.MCGILL.CA> AIKEN,
  1233. INRA000@MUSICB.MCGILL.CA writes:
  1234. >     Can anyone think of a reasonably robust way of coercing OpenPicture
  1235. > into allocating its picture using temporary memory?
  1236.  
  1237. Aaron Giles' solution of switching to the temp-mem zone is explicitly
  1238. non-kosher; IM warns not to do anything with the parent zone of temp handles.
  1239. I _think_ the only bad thing that will happen, pre-Copland, is that the
  1240. handle will not automatically be disposed when your app quits. If you make
  1241. sure it's always disposed, this shouldn't be a problem. In a modern-OS
  1242. system, though, this might break.
  1243.  
  1244. Other approaches I can think of:
  1245. * Call OpenPicture, then call NewTempHandle and copy the data from
  1246. thePort->picSave handle into the temp handle, then modify thePort->picSave to
  1247. point to the temp handle (and dispose the original one.)
  1248. * Temporarily patch NewHandle during the OpenPicture call, and have the patch
  1249. call NewTempHandle.
  1250.  
  1251.  
  1252. --Jens Alfke
  1253.   jens_alfke@powertalk              Rebel girl, rebel girl,
  1254.             .apple.com              Rebel girl you are the queen of my world
  1255.  
  1256. +++++++++++++++++++++++++++
  1257.  
  1258. >From giles@med.cornell.edu (Aaron Giles)
  1259. Date: Thu, 28 Jul 1994 11:02:18 -0400
  1260. Organization: Cornell University Medical College
  1261.  
  1262. In article <1994Jul27.202849.19507@gallant.apple.com>, Jens Alfke
  1263. <jens_alfke@powertalk.apple.com> wrote:
  1264.  
  1265. > Aaron Giles' solution of switching to the temp-mem zone is explicitly
  1266. > non-kosher; IM warns not to do anything with the parent zone of temp handles.
  1267.  
  1268. Must've missed that warning, but I figured what I was doing was bad
  1269. anyway. :-)  Thanks for the "cleaner" suggestions! (cleaner being a very
  1270. relative term here)
  1271.  
  1272. Aaron
  1273. -- 
  1274. Aaron Giles (giles@med.cornell.edu)
  1275. Power Macintosh Developer, Cornell University Medical College
  1276. JPEGView home page: http://www.med.cornell.edu/jpegview.html
  1277. JPEGView FTP site:   ftp://ftp.med.cornell.edu/pub/aarong/jpegview/
  1278.  
  1279. +++++++++++++++++++++++++++
  1280.  
  1281. >From jmunkki@beta.hut.fi (Juri Munkki)
  1282. Date: 29 Jul 1994 22:54:13 GMT
  1283. Organization: Helsinki University of Technology
  1284.  
  1285. In article <1994Jul27.202849.19507@gallant.apple.com> Jens Alfke <jens_alfke@powertalk.apple.com> writes:
  1286. >Aaron Giles' solution of switching to the temp-mem zone is explicitly
  1287. >non-kosher; IM warns not to do anything with the parent zone of temp handles.
  1288. >I _think_ the only bad thing that will happen, pre-Copland, is that the
  1289. >handle will not automatically be disposed when your app quits. If you make
  1290. >sure it's always disposed, this shouldn't be a problem. In a modern-OS
  1291. >system, though, this might break.
  1292.  
  1293. It probably couldn't be made very compatible with old versions of the
  1294. MultiFinder in any case and some of us (don't look at me though) want
  1295. to support System 6.
  1296.  
  1297. >Other approaches I can think of:
  1298. >* Call OpenPicture, then call NewTempHandle and copy the data from
  1299. >thePort->picSave handle into the temp handle, then modify thePort->picSave to
  1300. >point to the temp handle (and dispose the original one.)
  1301.  
  1302. Sounds dangerous to me, although I'm pretty sure this is safe at least now.
  1303.  
  1304. >* Temporarily patch NewHandle during the OpenPicture call, and have the patch
  1305. >call NewTempHandle.
  1306.  
  1307. Patch???? For something as simple as this? Patches are a necessary evil in
  1308. some cases, but should be avoided when there's a better solution. Besides,
  1309. this will break if QD decides that it needs to load a resource or create
  1310. some other handle when it does the OpenPicture, because the other handle will
  1311. also be temp memory even though it shouldn't.
  1312.  
  1313. In any case, why not just save the QD bottleneck that handles saving pictures.
  1314. You keep a regular handle for the header of the picture and write the data
  1315. into temporary memory. For example code on how this is done, just read the
  1316. IM chapter that has the example on how to write a picture to disk and replace
  1317. the file system calls with temporary memory calls.
  1318.  
  1319. -- 
  1320.   Juri Munkki            There ain't no such thing as a shareware lunch.
  1321.  jmunkki@hut.fi                Windsurfing: Faster than the wind.
  1322.  
  1323. ---------------------------
  1324.  
  1325. >From cabo@mi.aau.dk (Christian Orellana)
  1326. Subject: QuickTime 2.0 and MIDI
  1327. Date: Mon, 25 Jul 1994 21:34:49 GMT
  1328. Organization: aau
  1329.  
  1330.  
  1331. Hi!
  1332. I understand that some music extension is needed to make QuickTime 2.0 interact
  1333. with MIDI. Does anybody know the details of this product? like:
  1334.  
  1335. a) Is this an existing product?
  1336. b) Where do I get it?
  1337. c) How does it work; does it cooperate with the midi manager? 
  1338. d) Does it support general midi pacthes only, or can one add custom sounds?
  1339. e) Is it implemented as a component?
  1340.  
  1341. Best regards -
  1342. Christian A.Borlund Orellana
  1343. Institute of Physics and Astronomy Aarhus University.
  1344. ______________________________________________________
  1345. Internet e-mail:        muscabo@dfi.aau.dk
  1346. voice:                  +45-86102798
  1347. mail:                   Dr.Margrethesvej 11,3.th.
  1348.                         8200 Aarhus N, DENMARK.
  1349. ______________________________________________________
  1350.  
  1351.  
  1352. +++++++++++++++++++++++++++
  1353.  
  1354. >From rmah@panix.com (Robert Mah)
  1355. Date: 26 Jul 1994 20:51:28 GMT
  1356. Organization: One Step Beyond
  1357.  
  1358. cabo@mi.aau.dk (Christian Orellana) wrote:
  1359.  
  1360. ) I understand that some music extension is needed to make QuickTime 2.0
  1361. ) interact with MIDI. Does anybody know the details of this product? like:
  1362. ) a) Is this an existing product?
  1363.  
  1364. Has been announced.  Was on the latest developer CD.  I'm not sure if 
  1365. it's available to the general public or shipping with new machines yet.
  1366.  
  1367. ) b) Where do I get it?
  1368.  
  1369. Apple.  You can get the QT developer's kit from APDA.
  1370.  
  1371. ) c) How does it work; does it cooperate with the midi manager? 
  1372.  
  1373. I haven't looked at it closely, but from the general description, I think
  1374. it implements the General MIDI spec (or parts of it).  That is, it contains
  1375. samples for a variety of instruments at various pitches and probably allows
  1376. you to play them by note.
  1377.  
  1378. ) d) Does it support general midi pacthes only, or can one add custom sounds?
  1379. ) e) Is it implemented as a component?
  1380.  
  1381. Don't know.  Anyone looked at the extension on the CD closer yet?
  1382.  
  1383. Cheers,
  1384. Rob
  1385. _____________________________________________________________________
  1386. Robert S. Mah           Software Development          +1.212.947.6507
  1387. One Step Beyond        and Network Consulting          rmah@panix.com
  1388.  
  1389. +++++++++++++++++++++++++++
  1390.  
  1391. >From quesnel@sound.music.mcgill.ca (Rene Quesnel)
  1392. Date: Wed, 27 Jul 1994 11:44:47 GMT
  1393. Organization: Faculty of Music, McGill University
  1394.  
  1395. Christian Orellana (cabo@mi.aau.dk) wrote:
  1396.  
  1397. > Hi!
  1398. > I understand that some music extension is needed to make QuickTime 2.0 interact
  1399. > with MIDI. Does anybody know the details of this product? like:
  1400.  
  1401. > a) Is this an existing product?
  1402. > b) Where do I get it?
  1403. > c) How does it work; does it cooperate with the midi manager? 
  1404. > d) Does it support general midi pacthes only, or can one add custom sounds?
  1405. > e) Is it implemented as a component?
  1406.  
  1407. There is a short document "QuickTime 2.0 Information" available at
  1408. ftp.support.apple.com in directory 
  1409. /pub/Apple SW Updates /Macintosh/Supplemental System Software/.
  1410. It doesn't say much but it's a start.
  1411.  
  1412. Rene Quesnel
  1413.  
  1414. Music Technology and Sound Recording Areas
  1415. Faculty of Music, McGill University
  1416. Montreal, QC, Canada
  1417. e-mail: quesnel@music.mcgill.ca
  1418.  
  1419.  
  1420. +++++++++++++++++++++++++++
  1421.  
  1422. >From andreas@sctc.com (Glenn Andreas)
  1423. Date: Wed, 27 Jul 1994 15:37:11 GMT
  1424. Organization: SCTC
  1425.  
  1426. rmah@panix.com (Robert Mah) writes:
  1427.  
  1428. >cabo@mi.aau.dk (Christian Orellana) wrote:
  1429.  
  1430. >) I understand that some music extension is needed to make QuickTime 2.0
  1431. >) interact with MIDI. Does anybody know the details of this product? like:
  1432. >) 
  1433.  
  1434. >) c) How does it work; does it cooperate with the midi manager? 
  1435.  
  1436. >I haven't looked at it closely, but from the general description, I think
  1437. >it implements the General MIDI spec (or parts of it).  That is, it contains
  1438. >samples for a variety of instruments at various pitches and probably allows
  1439. >you to play them by note.
  1440.  
  1441. >) d) Does it support general midi pacthes only, or can one add custom sounds?
  1442. >) e) Is it implemented as a component?
  1443.  
  1444. >Don't know.  Anyone looked at the extension on the CD closer yet?
  1445.  
  1446. Actually, the "Music Component Architecture" (or something like that) isn't
  1447. MIDI.  However, with MoviePlayer 2.0 you can convert MIDI files to QuickTime
  1448. movies that just contain the (music) sound track.  Also, if you have a MIDI
  1449. output device, you can have QuickTime convert the music to play on the MIDI
  1450. device.  Don't know if there are any simple, direct ways to input from a
  1451. MIDI device, since I don't own one.
  1452.  
  1453. There are actually three different components - the Music Component (a low
  1454. level component that you aren't suppose to talk to), the Note Allocator, and
  1455. the Tune Player.  You basically set up a bunch of commands, similar to MIDI
  1456. (there are note commands, rest commands, knob commands, general commands,
  1457. control commands, etc...), and send them to the Tune Player.
  1458.  
  1459. The Music Component (there are actually two - built in synthesizer, and
  1460. "general MIDI device") is the thing that actually either plays them via
  1461. the sound manager, or converts them to MIDI.  The note allocator sits between
  1462. the two and figures out how to manage the music component based on the needs
  1463. of the tune player.
  1464.  
  1465. All in all, once you've figured it out, it works quite well, especially for
  1466. things such as adding background music to games (for example).  BTW, I've
  1467. recently written an article that will hopefully appear in an upcoming
  1468. MacTech explaining the basic format of music commands and the tune player.
  1469.  
  1470. Glenn Andreas
  1471.  
  1472.  
  1473. +++++++++++++++++++++++++++
  1474.  
  1475. >From rmah@panix.com (Robert Mah)
  1476. Date: 27 Jul 1994 20:47:57 GMT
  1477. Organization: One Step Beyond
  1478.  
  1479. andreas@sctc.com (Glenn Andreas) wrote:
  1480.  
  1481. ) Actually, the "Music Component Architecture" (or something like that)
  1482. ) isn't MIDI.  However, with MoviePlayer 2.0 you can convert MIDI files
  1483. ) to QuickTime movies that just contain the (music) sound track.  Also,
  1484. ) if you have a MIDI output device, you can have QuickTime convert the
  1485. ) music to play on the MIDI device.  Don't know if there are any simple,
  1486. ) [...]
  1487.  
  1488. Sounds cool, though it's too bad Apple didn't try harder to conform with
  1489. the General MIDI standard.  Oh well.
  1490.  
  1491. Do you know where I could pick up the docs on this stuff?  I searched
  1492. the latest developer CD with QT 2.0 on it, but couldn't find any info.
  1493. Some special, new Apple multimedia FTP site perchance?
  1494.  
  1495. Cheers,
  1496. Rob
  1497. _____________________________________________________________________
  1498. Robert S. Mah           Software Development          +1.212.947.6507
  1499. One Step Beyond        and Network Consulting          rmah@panix.com
  1500.  
  1501. +++++++++++++++++++++++++++
  1502.  
  1503. >From aclaasse@nyx.cs.du.edu (Arne Claassen)
  1504. Date: 27 Jul 1994 22:52:49 -0600
  1505. Organization: University of Denver, Dept. of Math & Comp. Sci.
  1506.  
  1507. In article <rmah-2707940250560001@rmah.dialup.access.net>,
  1508. Robert Mah <rmah@panix.com> wrote:
  1509. >Sounds cool, though it's too bad Apple didn't try harder to conform with
  1510. >the General MIDI standard.  Oh well.
  1511.  
  1512. In what respect? The story i got was that Roland liscensen them their GS
  1513. seris sounds for Quicktime 2.0. Only a subset of the entire GM set is supposed
  1514. to be in QT 2.0, but the rest can be added by developers if needed.
  1515. The internal format is not a standard midifile, but if a MIDI device is 
  1516. present (i'd have to assume that QT 2.0 works with MIDI Manager) it will
  1517. play through to the midi device. At least that's what the propaganda claimed.
  1518.  
  1519. Arne F. Claassen     claassen@ebs330.eb.uah.edu
  1520.  
  1521.  
  1522. +++++++++++++++++++++++++++
  1523.  
  1524. >From al@crucible.powertools.com (Al Evans)
  1525. Date: 29 Jul 94 14:35:21 GMT
  1526. Organization: PowerTools, Austin, Texas
  1527.  
  1528. In article <317dj1$b0h@nyx.cs.du.edu> aclaasse@nyx.cs.du.edu (Arne Claassen) writes:
  1529.  
  1530. >In article <rmah-2707940250560001@rmah.dialup.access.net>,
  1531. >Robert Mah <rmah@panix.com> wrote:
  1532. >>Sounds cool, though it's too bad Apple didn't try harder to conform with
  1533. >>the General MIDI standard.  Oh well.
  1534.  
  1535. >In what respect? The story i got was that Roland liscensen them their GS
  1536. >seris sounds for Quicktime 2.0. Only a subset of the entire GM set is supposed
  1537. >to be in QT 2.0, but the rest can be added by developers if needed.
  1538.  
  1539. If the QuickTime 2.0 music-playing routines "conformed with the General
  1540. MIDi standard," you would be able to play to a note-allocator 
  1541. NoteChannel just like you would to a real MIDI device. This is not
  1542. feasible beyond a certain elementary level (i.e., note-on, note-off,
  1543. and perhaps controller events). A simple example: using the built-in
  1544. synthesizer, a program change cannot be implemented in real time, since
  1545. it requires loading a new sound sample from the disk (which is slow)
  1546. and you can't do it at interrupt time.
  1547.  
  1548. Actually, according to *one* Apple tech support person, you're not 
  1549. allowed to make ANY note allocator calls at interrupt time. I dismissed
  1550. this as improbable, since the note allocator has no built-in timing
  1551. facilities (as does the Midi Manager, for example). So far, I have
  1552. had no trouble calling NAPlayNote(), at least, from an interrupt 
  1553. handler -- I was told by another Apple tech support person that this
  1554. was legal.
  1555.                     --Al Evans--
  1556. -- 
  1557. Al Evans        |   Graphic Elements: A new standard for 
  1558. ________________________|__ high-performance interactive Macintosh graphics.
  1559. al@crucible.powertools.com |  Available from mac.archive.umich.edu
  1560. - -------------------------| /mac/development/libraries/graphicelements2.sit.hqx
  1561.  
  1562. ---------------------------
  1563.  
  1564. >From rcostale@nmsu.edu (Raphael J. Costales)
  1565. Subject: Tab Patch for TextEdit
  1566. Date: 29 Jul 1994 05:22:07 GMT
  1567. Organization: New Mexico State University, Las Cruces, NM
  1568.  
  1569. /***************************************************************************
  1570.  
  1571.     tab_patch.c
  1572.  
  1573.     A while back, jesjones@stein.u.washington.edu posted some code written
  1574. in Modula-2 for three patches to TextEdit.  These patches enable TextEdit to
  1575. display tab characters as a run of spaces.  The three routines are:
  1576.  
  1577.     1.  DrawText
  1578.     2.  TextWidth
  1579.     3.  Pixel2Char (System 6)
  1580.         NPixel2Char (System 7)
  1581.  
  1582.     I rewritten the code in C in Think C ver. 4 using System 6 and tested it
  1583. on a Mac Plus - eight years old, but it still works fine!  I just wrote the
  1584. Pixel2Char, but NPixel2Char would be handled the same way.  The three patches
  1585. work the same way.  They expand tab characters into spaces then call the
  1586. original routine.
  1587.  
  1588.     Note, Pixel2Char & NPixel2Char are not real traps.  They use a generic
  1589. trap, ScriptUtil, after pushing a selector on the stack (see IM V).  Because
  1590. ScriptUtil takes a varying number of arguments, some assembly is required -
  1591. excuse the pun.
  1592.  
  1593.     Fell free to send any comments or suggestions other than buy a new Mac!
  1594.  
  1595.     rcostale@nmsu.edu
  1596.  
  1597. ***************************************************************************/
  1598.  
  1599. #define TABLEN      4           /* Tab length */
  1600. #define MAXSIZE     256         /* Size of Buffer.  Any text expanded beyond
  1601.                                  * the size of the buffer won't be displayed
  1602.                                  */
  1603.  
  1604. extern WindowPtr myWindow;      /* Of course, these would be your working */
  1605. extern TEHandle TEH;            /* Window pointer and TextEdit handle */
  1606.  
  1607. static pascal void  DoTrap();
  1608.  
  1609. pascal void newDrawText(char *, short, short);
  1610. pascal int  newTextWidth(char *, short, short);
  1611. pascal int  newPixel2Char(char *, short, short, short, Boolean *, long);
  1612.  
  1613. ProcPtr     oldDrawText, oldTextWidth, oldPixel2Char;
  1614.  
  1615. TabsOn()    /* Install patches */
  1616. {
  1617.     /* The first two patches are straight forward */
  1618.  
  1619.     oldDrawText = (ProcPtr) NGetTrapAddress(0xA885, ToolTrap);
  1620.     oldTextWidth = (ProcPtr) NGetTrapAddress(0xA886, ToolTrap);
  1621.  
  1622.     NSetTrapAddress((long) newDrawText, 0xA885, ToolTrap);
  1623.     NSetTrapAddress((long) newTextWidth, 0xA886, ToolTrap);
  1624.  
  1625.     /* The Pixel2Char uses the generic trap ScriptUtil.  We will patch in
  1626.      * an assembly routine that test the selector
  1627.      */
  1628.  
  1629.     oldPixel2Char = (ProcPtr) NGetTrapAddress(0xA8B5, ToolTrap);
  1630.     NSetTrapAddress((long) DoTrap, 0xA8B5, ToolTrap);
  1631. }
  1632.  
  1633. TabsOff()   /* Remove the patches when you're application finishes! */
  1634. {
  1635.     NSetTrapAddress((long) oldDrawText, 0xA885, ToolTrap);
  1636.     NSetTrapAddress((long) oldTextWidth, 0xA886, ToolTrap);
  1637.     NSetTrapAddress((long) oldPixel2Char, 0xA8B5, ToolTrap);
  1638. }
  1639.  
  1640. /* The assembly routine to check selector */
  1641. static pascal void DoTrap()
  1642. {
  1643.     long    selector = 0x820E0014;  /* or 0x8222002 for NPixel2Char */
  1644.  
  1645.     asm {
  1646.         move.l  selector, d0
  1647.         unlk    a6
  1648.         cmp.l   4(sp), d0           /* Is it the Pixel2Char selector? */
  1649.         bne.s   @old                /* No, do old oldPixel2Char */
  1650.         jmp     newPixel2Char       /* Yes, do patch */
  1651. @old
  1652.         move.l  oldPixel2Char, a0
  1653.         jmp     (a0)
  1654.     }
  1655. }
  1656.  
  1657. pascal void newDrawText(char textPtr[], short first, short count)
  1658. {
  1659.     char    buffPtr[MAXSIZE] = {0};
  1660.     int     buffCount;
  1661.  
  1662.     /* if were using my window then expand the text into the buffer and
  1663.      * call the original routine using the buffer.
  1664.      */
  1665.  
  1666.     if (FrontWindow() == myWindow) {
  1667.         buffCount = tab2spaces(textPtr + first, buffPtr, count);
  1668.         CallPascal(buffPtr, 0, buffCount, oldDrawText);
  1669.     }
  1670.     else
  1671.         CallPascal(textPtr, first, count, oldDrawText);
  1672. }
  1673.  
  1674. pascal int newTextWidth(char textPtr[], short first, short count)
  1675. {
  1676.     char    buffPtr[MAXSIZE] = {0};
  1677.     int     buffCount;
  1678.  
  1679.     /* same idea here */
  1680.  
  1681.     if (FrontWindow() == myWindow) {
  1682.         buffCount = tab2spaces(textPtr + first, buffPtr, count);
  1683.         return CallPascalW(buffPtr, 0, buffCount, oldTextWidth);
  1684.     }
  1685.     else
  1686.         return CallPascalW(textPtr, first, count, oldTextWidth);
  1687. }
  1688.  
  1689. /* This function converts tabs to spaces and places the text in a buffer.
  1690.  * It also returns the size of the buffer.
  1691.  */
  1692. int tab2spaces(char textPtr[], char buffPtr[], short count)
  1693. {
  1694.     char    chr;
  1695.     int     i, j, buffCount, spc;
  1696.  
  1697.     i = j = spc = 0;
  1698.     buffCount = offset(textPtr);
  1699.     for (i = 0; i < count; i++) {
  1700.         switch (chr = textPtr[i]) {
  1701.         case '\t':
  1702.             spc = TABLEN - (buffCount % TABLEN);
  1703.             while (spc--) {
  1704.                 buffPtr[j++] = ' ';
  1705.                 buffCount++;
  1706.             }
  1707.             break;
  1708.         case '\r':
  1709.             buffCount = 0;
  1710.         default:
  1711.             buffPtr[j++] = chr;
  1712.             buffCount++;
  1713.         }
  1714.     }
  1715.     return j;
  1716. }
  1717.  
  1718. /* This function finds the offset from the start of a line. */
  1719. int offset(char textPtr[])
  1720. {
  1721.     char   *linePtr, *charPtr;
  1722.     int     i = 0;
  1723.  
  1724.     linePtr = textPtr;
  1725.  
  1726.     /* find start of line */
  1727.  
  1728.     while ((linePtr > (*(**TEH).hText)) && (*linePtr != '\r'))
  1729.         linePtr--;
  1730.  
  1731.     /* find offset */
  1732.  
  1733.     for (charPtr = linePtr; charPtr < textPtr; charPtr++)
  1734.         switch (*charPtr) {
  1735.         case '\t':
  1736.             i = i + TABLEN - (i % TABLEN);
  1737.             break;
  1738.         case '\r':
  1739.             i = 0;
  1740.             break;
  1741.         default:
  1742.             i++;
  1743.         }
  1744.     return i;
  1745. }
  1746.  
  1747. /* Note, the selector is not an actual parameter. The selector is push on to
  1748.  * the stack before issuing the ScriptUtil trap.  Since the Pascal calling
  1749.  * convention pushes parametes from left-to-right, the selector is right above
  1750.  * the return address.  Use NPixel2Char declaration if you're using System 7.
  1751.  */
  1752. pascal int newPixel2Char(char textPtr[], short count, short slop, short width,
  1753.                          Boolean *leadingEdge, long selector)
  1754. {
  1755.     char    buffPtr[MAXSIZE] = {0};
  1756.     int     buffCount, pos;
  1757.  
  1758.     /* Again, we expand the text into a buffer and call the original trap */
  1759.  
  1760.     if (FrontWindow() == myWindow) {
  1761.         buffCount = tab2spaces(textPtr, buffPtr, count);
  1762.         pos = CallPascalW(buffPtr, buffCount, slop, width, &leadingEdge,
  1763.                           selector, oldPixel2Char);
  1764.         return charPos(textPtr, pos);
  1765.     }
  1766.     else
  1767.         return CallPascalW(textPtr, count, slop, width, &leadingEdge,
  1768.                            selector, oldPixel2Char);
  1769. }
  1770.  
  1771. /* returns the character position in the actual text corresponding to
  1772.  * position in the buffer.
  1773.  */
  1774. int charPos(char textPtr[], int pos)
  1775. {
  1776.     char   *linePtr;
  1777.     int i = 0, j =0 ;
  1778.  
  1779.     linePtr = textPtr;
  1780.     while ((linePtr > (*(**TEH).hText)) && (*linePtr != '\r'))
  1781.         linePtr--;
  1782.  
  1783.     while (i < pos) {
  1784.         switch (*linePtr) {
  1785.         case '\t':
  1786.             i = i + TABLEN - (i % TABLEN);
  1787.             j++;
  1788.             break;
  1789.         case '\r':
  1790.             i = j = 0;
  1791.             break;
  1792.         default:
  1793.             i++; j++;
  1794.         }
  1795.         linePtr++;
  1796.     }
  1797.     return j;
  1798. }
  1799.  
  1800. -- 
  1801. +------+
  1802. |      | Raphael J.S. Costales
  1803. | NMSU | rcostale@nmsu.edu
  1804. |  *___| New Mexico State University
  1805.  
  1806. ---------------------------
  1807.  
  1808. >From cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton)
  1809. Subject: [Q] Increasing stack size?
  1810. Date: Fri, 29 Jul 1994 11:27:07 -0600
  1811. Organization: Academic Computing, UT-Houston
  1812.  
  1813. Can anyone think of a reason why a program that runs fine on most every Mac
  1814. model ends up with a stack (not heap) that runs out of space on a SE or
  1815. Plus? Is there something different that Think C (or CodeWarrior, for that
  1816. matter) must do on a 68K Mac that would cause it to eat significantly more
  1817. stack space? FWIW the app is MacHTTP, so it's playing with MacTCP,
  1818. AppleScript (if available), and AppleTalk (if required by MacTCP).
  1819.  
  1820. Stack space and heap space come out of the same chunk of memory allocated
  1821. to the application, correct? Is it possible that one of the aforementioned
  1822. software elements may eat up a bunch of memory on a Plus or SE? The
  1823. confusing thing is that frequent checks of available RAM show nothing amiss
  1824. while the program is running, yet it ends up with a corrupted stack
  1825. (because it runs out of space?)
  1826.  
  1827. --_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
  1828. Chuck Shotton                             \ 
  1829. Assistant Director, Academic Computing     \   "Are we there yet?"
  1830. U. of Texas Health Science Center Houston   \ 
  1831. cshotton@oac.hsc.uth.tmc.edu  (713) 794-5650 \ 
  1832. _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\-_-_-_-_-_-_-_-_-_-_-_-_-
  1833.  
  1834. +++++++++++++++++++++++++++
  1835.  
  1836. >From larson@oahu.cs.ucla.edu (Christopher Larson)
  1837. Date: Fri, 29 Jul 94 18:36:15 GMT
  1838. Organization: UCLA, Computer Science Department
  1839.  
  1840. In article <cshotton-290794112707@oac2.hsc.uth.tmc.edu> cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1841. >Can anyone think of a reason why a program that runs fine on most every Mac
  1842. >model ends up with a stack (not heap) that runs out of space on a SE or
  1843. >Plus?
  1844.  
  1845. Sure. Neither of those machines has Color Quickdraw. On machines without CQD,
  1846. the default stack size is (I believe) 8K, but on a machine with CQD (as most
  1847. Macs out there today are) the default stack size is 32K. Your program must
  1848. use stack space larger than 8K and smaller than 32K -- hence it works on
  1849. CQD machines but not the old ones.
  1850.  
  1851. >Stack space and heap space come out of the same chunk of memory allocated
  1852. >to the application, correct?
  1853.  
  1854. Yup.
  1855.  
  1856. >Is it possible that one of the aforementioned
  1857. >software elements may eat up a bunch of memory on a Plus or SE?
  1858.  
  1859. I doubt they eat any _more_ on a Plus or SE than on other machines; whether
  1860. or not they eat up a 'bunch' is left as an exercise for the reader ;-).
  1861.  
  1862. >The
  1863. >confusing thing is that frequent checks of available RAM show nothing amiss
  1864. >while the program is running, yet it ends up with a corrupted stack
  1865. >(because it runs out of space?)
  1866.  
  1867. Are you checking the amount of free stack space during runtime (other than
  1868. by watching the stack sniffer inititate a system error)? During development,
  1869. you should try to max out the stack usage and then call StackSpace() to
  1870. determine your stack usage. If this usage is larger than the smallest default
  1871. stack size, you should expand the stack to accomidate for this difference.
  1872. (E.g. if you find that your program uses 20K of stack space, you should
  1873. expand the stack by at least 12K (perhaps a little more for cushioning) in
  1874. the initialization phase of your program.)
  1875.  
  1876. Techniques for expanding the stack and the details of the StackSpace() call
  1877. can be found in Inside Macintosh: Memory.
  1878.  
  1879. --Chris
  1880. _______________________________________________________________________________
  1881. Chris Larson -- Amateur Macintosh Geek, CoBase Research Assistant
  1882. L.A. Institute of Slowly and Painfully Working Out the Surprisingly Obvious
  1883. Death to the Trojans! Go Bruins!
  1884.  
  1885. (Insert disclaimer here)
  1886. Internet: larson@kingston.cs.ucla.edu
  1887.  
  1888. ---------------------------
  1889.  
  1890. End of C.S.M.P. Digest
  1891. **********************
  1892.  
  1893.  
  1894. ˇ